Repository navigation
Report MSBuild test task failures and fix pipe listener and log lifetime - #12711
Azat Mukhametshin (azat-msft) wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🧪 Test quality review — PR #12711
Compared merge base 355f7b998694601aa5a5163bb6ee2ff9e8d06fb3 with head b33306dc32015f1a714f874058ea4146aa7b921f. Evidence applies to this head only.
Test-value evidence
All results are static predictions. No paired execution records were available, and no tests were run.
| Contract | Test / decisive assertion | Counterfactual | Evidence |
|---|---|---|---|
Log-creation IOException or UnauthorizedAccessException fails the task with a reported error and no MSB6003 |
Execute_OutputFileCreationFailureFailsTask (4 data rows): Assert.IsFalse(Execute()), the message is in errors, no MSB6003, and the exact error count |
Before the fix the exception escapes the task, so DoesNotContain MSB6003 and IsFalse should fail |
Static prediction: likely killed |
| A writer-initialization failure disposes the stream and fails the task | Execute_OutputWriterInitializationFailureDisposesStreamAndFailsTask: stream.CanWrite is false, the flush error is reported, IsFalse(Execute()) |
Without the output.Dispose() in the catch, the stream stays writable |
Static prediction: likely killed |
Pipe server disposal and token use, Dispose() in finally, _hasInfrastructureError handling |
No dedicated test | Dropping the finally disposal or the pipe cleanup would not be detected by the new tests |
Unverified. Not asserted by the new tests (a gap, not a proven defect). |
PACKAGE.md wording |
None | None | Not applicable (documentation) |
🧵 Parallel safety
The parallel-safety-reviewer specialist subtask was not run in this pass, so coverage is incomplete: STATUS: PARTIAL. Static inspection of the changed tests found no cross-test hazards. Each test creates its own AppHostTaskFixture, StubFileSystem and MemoryStream. No parallelization configuration changed. Treat this as unconfirmed; re-run /parallel-audit for a full result.
Per-test assessment
Pseudo-mutation evidence below consists of static predictions, not executed mutation results.
| Result | Quality | Test | Notes | Follow-up |
|---|---|---|---|---|
| Pass | A (90–100) | new InvokeTestingPlatformTaskTests.Execute_OutputFileCreationFailureFailsTask |
Covers all four module and exception combinations with exact error counts and codes. | None |
| Pass | B (80–89) | new InvokeTestingPlatformTaskTests.Execute_OutputWriterInitializationFailureDisposesStreamAndFailsTask |
Asserts disposal and the reported flush error. It does not assert an exact error count. | No change justified: the claimed contract (stream disposed, failure reported) is protected. |
No inline comments were published.
<sub>This advisory review is heuristic and non-blocking.
Re-run the combined review with /review-tests, or only the parallel-safety specialist with /parallel-audit.</sub>
🤖 Automated content by GitHub Copilot. Generated by the Test Quality Review on PR (on open / sync) workflow. · copilot · auto (Claude Sonnet 5.5) · ~30 AIC · ⌖ ~2 AIC · ⊞ 8.5K
There was a problem hiding this comment.
🤖 Generated by Copilot expert-reviewer — workflow run
Reviewed PR #12711 (MSBuild task pipe-server lifetime, log-creation failure handling, new unit tests). No blocking issues found.
Verified
Resources.MSBuildResources.TestFailedNoDetailexists inMSBuildResources.resx(Tests failed: {0}, with a comment) and has xlf entries for all locales, so no localization work is missing.NamedPipeServer.WasConnectedexists and is set when a client connects.DisposeAsyncexists, so the#if NETsplit is valid.- Disposing the log after the connection loop and servers have stopped fixes the leaked-writer race described in the comment.
Non-blocking observations
_hasInfrastructureErroris a plain field written from pipe-handler and loop threads.Execute()reads it afterDispose(), which waits for the loop, so the final read is fine.HandleTaskExecutionErrorsruns earlier, insidebase.Execute(), and can race with a lateModuleInfoRequest. Considervolatile(orVolatile.Read/Write) for clarity.Execute()now callsDispose()infinally, and callers may dispose again (usingin tests, MSBuild). Please confirmNamedPipeServer.Dispose()is idempotent. A secondDispose()on an already disposed server in_connectionsshould be a no-op. A short test with a doubleDispose()would lock this in.- In
HandleTaskExecutionErrors, the_hasInfrastructureError && ExitCode == -1short-circuit relies on ToolTask's behaviour of turning exit code 0 into -1 when errors were logged. A real exit code of -1 combined with an infrastructure error would also be swallowed. That is acceptable, since the error was already reported. - The
TryInitializeOutputFilecatch only coversIOExceptionandUnauthorizedAccessException. That matches the intent, and the tests exercise both exceptions.
Test-value evidence
Not executed (read-only review). By static prediction, Execute_OutputFileCreationFailureFailsTask fails on the base revision because the exception goes unhandled on the pipe connection (the test asserts no MSB6003). The writer-initialization test covers the stream-disposal path. I could not confirm red/green runs from the diff alone.
b33306d to
7702ef4
Compare
|
/review |
|
✅ Expert Code Review (command) completed successfully! Expert Code Review (command)Outcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the infrastructure-error reporting and resource-cleanup changes.
No open issues 🎉
What changed in this PR
Builds on #12710 to make Microsoft.Testing.Platform’s MSBuild task report infrastructure failures accurately and clean up pipe and log resources reliably.
Changes:
- Reports log-creation and connection-loop failures without misleading test-failure messages.
- Adds guaranteed cleanup, cancellation-aware pipe servers, and safer log disposal ordering.
- Adds failure-path regression tests and documents log-creation errors.
Confidence at a glance
🟡 MSBuild task validation
Test-value evidence: The author reports five regression cases failing without the fixes and passing on the submitted revision. Acceptance tests passed one revision earlier. Execution artifacts were not independently verified; pipe cleanup and disposal ordering remain untested.
| File | Description |
|---|---|
test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/InvokeTestingPlatformTaskTests.cs |
Tests log-creation failures, error reporting, and stream cleanup. |
src/MTP/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.Execution.cs |
Handles infrastructure failures and guarantees execution cleanup. |
src/MTP/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.cs |
Tracks infrastructure errors and closes pipes before the log. |
src/MTP/Microsoft.Testing.Platform.MSBuild/PACKAGE.md |
Documents MSBuild errors when log creation fails. |
Review effort: Balanced
There was a problem hiding this comment.
🤖 Reviewed by Copilot (expert-reviewer) — workflow run
Summary: No blocking findings. I reviewed the diff statically and did not execute the PR's code.
Verified
Resources.MSBuildResources.TestFailedNoDetailalready exists inMSBuildResources.resx(line 161) and in all the.xlffiles. The PR adds no resource, so no localization regeneration is needed.NamedPipeServer.WasConnectedexists as a public getter, so the newfinallydispose check compiles._hasInfrastructureErrorisvolatile, which suits its writes from pipe-connection threads and its read on the task thread.Dispose()now disposes the log stream only after the connection loop and all servers have stopped. That closes the leak where a lateModuleInfoRequestcreates a log after disposal.Execute()callsDispose()in afinally._waitForConnections.Cancel()moved intoDispose(), so the cancel still happens.TryInitializeOutputFiledisposes the raw stream if theStreamWriterconstructor throws. It catches onlyIOExceptionandUnauthorizedAccessException, so unrelated bugs still surface.- The change adds no public API. The
PACKAGE.mdsentence matches the new behavior.
Non-blocking notes
Dispose()is now called both inExecute()and possibly by the caller.Cancel()andWait()are idempotent, but confirm thatserverInstance.Dispose()and_outputFileStream?.Dispose()tolerate a second call, which is true of the framework types.- A server created with
_waitForConnections.Tokencan cancel its own read loop at task end. This is intended, but the tests only cover this indirectly. - The tests cover creation failure (IO and access denied, with and without a module). A short test that a failed first
ModuleInfoRequestlets a later one retry would lock in the_moduleInfoassignment ordering.
Test-value evidence: Static assessment only. The new tests target the reported defect (a log-creation failure must fail the task). I did not run them and did not check them against the pre-fix revision.
7702ef4 to
d758a69
Compare
|
/review |
There was a problem hiding this comment.
🧪 Test quality review — PR #12711
Compared merge base d807174f039e1e7afb446a3b44c6eca56fae4c96 with head 7702ef4c961e740647a59f79cebd22bce2ad06f0. Evidence applies to this head, not every intermediate commit.
Test-value evidence
All entries are static predictions. No paired execution records were available, and this workflow does not run tests.
| Contract | Test and decisive assertion | Counterfactual | Result |
|---|---|---|---|
| A log-creation IO or access failure fails the task with a reported error instead of throwing | Execute_OutputFileCreationFailureFailsTask (4 data rows): Assert.IsFalse(task.Execute()), the error message is present, and there is no MSB6003 |
Without the TryInitializeOutputFile catch, the exception escapes the pipe handler and the task could succeed or surface MSB6003 |
Static prediction: likely detected |
Error count: one error when a module exists, otherwise two including run failed |
The same test, HasCount(1) and HasCount(2) with ContainsSingle("run failed") |
Without the _hasInfrastructureError handling in HandleTaskExecutionErrors and Execute, the count or the run failed error would differ |
Static prediction: likely detected |
| A stream is disposed when writer initialization throws | Execute_OutputWriterInitializationFailureDisposesStreamAndFailsTask: Assert.IsFalse(stream.CanWrite) plus the flush error message |
Without output.Dispose() in the catch block, CanWrite stays true |
Static prediction: likely detected. StreamWriter.AutoFlush = true flushes in the setter, which triggers the failing Flush |
The connection loop passes the cancellation token, disposes never-connected servers, and Execute disposes in a finally |
No dedicated test | None | Unverified. This is untested pipe lifecycle behavior; I judge it low risk |
PACKAGE.md wording |
N/A | N/A | Not applicable (documentation) |
🧵 Parallel safety
STATUS: PARTIAL. The separate specialist task was not run. A manual look found that the new tests use per-test AppHostTaskFixture and StubFileSystem instances, with no shared static state or paths. This is not a full analysis. No parallelization configuration changed, and no [DoNotParallelize] concern was identified.
Per-test assessment
Pseudo-mutation evidence below consists of static predictions, not executed mutation results.
| Result | Quality | Test | Notes | Follow-up |
|---|---|---|---|---|
| Pass | A (90–100) | new InvokeTestingPlatformTaskTests.Execute_OutputFileCreationFailureFailsTask |
It checks the failure result, error message, absence of MSB6003 and exact error counts across 4 data rows. | None. |
| Pass | B (80–89) | new InvokeTestingPlatformTaskTests.Execute_OutputWriterInitializationFailureDisposesStreamAndFailsTask |
It checks disposal and the error message, but not the error count. | No change justified: the asserted contract (stream disposed, task fails with the error) is fully covered. |
No inline comments were queued. I found no supported defect or concrete improvement.
This advisory review is heuristic and non-blocking. Re-run the combined review with /review-tests, or only the parallel-safety specialist with /parallel-audit.
🤖 Automated content by GitHub Copilot. Generated by the Test Quality Review on PR (on open / sync) workflow. · copilot · auto (Claude Sonnet 5.5) · ~32 AIC · ⌖ ~2 AIC · ⊞ 8.5K
This comment has been minimized.
This comment has been minimized.
12b925a to
feed5d7
Compare
There was a problem hiding this comment.
🧪 Test quality review — PR #12711
Compared merge base 86ee20cad57f747fe9472ae3a85157485f3cf5c3 with head feed5d77b67fec0084bce8b29f8a8d55cc2c9e41. Evidence applies to this head, not every intermediate commit. This was a static, read-only review; no tests were run.
Test-value evidence
| Contract | Test / decisive assertion | Counterfactual | Evidence |
|---|---|---|---|
A log-creation IOException or UnauthorizedAccessException fails the task with an MSBuild error instead of escaping as MSB6003. |
Execute_OutputFileCreationFailureFailsTask, all 4 data rows. Asserts Execute() is false, the message is logged, and there is no MSB6003. |
Without TryInitializeOutputFile and _hasInfrastructureError, the exception escapes or the task reports success. |
Static prediction: likely killed. Unverified. |
| Failure of the unique fallback log name fails the task. | Execute_UniqueLogCreationFailureFailsTask. Asserts a single error and no created files. |
Reverting to the old unhandled second CreateNew throws instead. |
Static prediction: likely killed. |
A failed first ModuleInfoRequest does not claim the module, so a retry can create the log. |
Execute_ModuleInfoRetryCreatesLogAfterFailedFirstAttempt. Asserts the single created file is retry/...log. |
Assigning _moduleInfo before the log exists leaves no log for the retry. |
Static prediction: likely killed. |
The stream is disposed when StreamWriter initialization fails. |
Execute_OutputWriterInitializationFailureDisposesStreamAndFailsTask. Asserts stream.CanWrite is false and the flush error is logged. |
Removing the catch { output.Dispose(); throw; } leaves the stream writable. |
Static prediction: likely killed. |
Pipe-server cleanup and cancellation token, Dispose() in finally, and _hasInfrastructureError set when the connection loop fails. |
No dedicated test: NamedPipeServer is not exercised through the simulated task. |
Not assessed. | Unprotected by changed tests. Unverified. An existing test may cover it. |
PACKAGE.md wording. |
Not applicable (documentation). | Not applicable. | Not applicable. |
No accessible revision-matched execution records were inspected, so none of the above is executed evidence.
🧵 Parallel safety
PARALLEL-SAFETY RESULT
STATUS: PARTIAL
The parallel-safety-reviewer subtask was not run, so parallel-safety coverage is incomplete and this is not an all-clear. The changed tests use per-test fixtures, a StubFileSystem and a mocked IBuildEngine. I saw no shared static state in the diff, but that was not a full assembly analysis.
Per-test assessment
Pseudo-mutation evidence is static prediction, not executed mutation results.
| Result | Quality | Test | Notes | Follow-up |
|---|---|---|---|---|
| Pass | A (90–100) | new InvokeTestingPlatformTaskTests.Execute_OutputFileCreationFailureFailsTask |
Covers both exception types and the with/without-module paths, with exact error counts. | None. |
| Pass | A (90–100) | new InvokeTestingPlatformTaskTests.Execute_UniqueLogCreationFailureFailsTask |
Asserts the single error message and that no file was created. | None. |
| Pass | A (90–100) | new InvokeTestingPlatformTaskTests.Execute_ModuleInfoRetryCreatesLogAfterFailedFirstAttempt |
Asserts both the single error and the exact retry log path. | None. |
| Pass | B (80–89) | new InvokeTestingPlatformTaskTests.Execute_OutputWriterInitializationFailureDisposesStreamAndFailsTask |
Checks disposal and the logged message, but not the error count. | No change justified: the disposal assertion protects the claimed contract. |
This advisory review is heuristic and non-blocking. Re-run with /review-tests.
🤖 Automated content by GitHub Copilot. Generated by the Test Quality Review on PR (on open / sync) workflow. · copilot · auto (Claude Sonnet 5.5) · ~31 AIC · ⌖ ~2 AIC · ⊞ 8.5K
This comment has been minimized.
This comment has been minimized.
…time Follow-up to the pipe and task log hardening: - Report output-log creation failures as MSBuild errors and fail the task instead of letting the exception escape a pipe connection; retry log creation on a later ModuleInfoRequest. - Fail the task when the IPC connection loop fails, even if the child exited 0. - Dispose pipe servers that never received a client, tie them to the task's cancellation, always run Dispose(), and close the log only after the servers stop. - Document the log naming and pipe access behavior in PACKAGE.md. Co-authored-by: Amaury Levé <amauryleve@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The flag is set on pipe-connection threads and read on the task thread. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
86ee20c to
61453b3
Compare
feed5d7 to
4886753
Compare
There was a problem hiding this comment.
🧪 Test quality review — PR #12711
Compared merge base 61453b3df2615d55ff028b0f81e10f8162264974 with head 4886753c3027be58b45a5edec90b5f1f6f565fd2. Evidence applies to this head only. No existing review threads were present, and no earlier report covers this head.
Test-value evidence
All entries are static predictions. No paired execution records were accessible, and this workflow did not run tests.
| Contract | Test and decisive assertion | Counterfactual | Evidence |
|---|---|---|---|
| Log-creation IO or access failure fails the task with an MSBuild error, not an escaped exception | Execute_OutputFileCreationFailureFailsTask: IsFalse(Execute()), message present, no MSB6003 |
Without the TryInitializeOutputFile catch, the exception escapes the direct HandleRequestAsync call and the test errors |
Static: likely detected |
| Unique fallback name failure is reported | Execute_UniqueLogCreationFailureFailsTask: single error, no created files |
Unhandled fallback exception | Static: likely detected |
A failed first ModuleInfoRequest does not claim the module |
Execute_ModuleInfoRetryCreatesLogAfterFailedFirstAttempt: exact retry log path |
Assigning _moduleInfo before the log exists skips the retry |
Static: likely detected |
| Stream is disposed when writer initialization fails | Execute_OutputWriterInitializationFailureDisposesStreamAndFailsTask: IsFalse(CanWrite) |
Without output.Dispose() in the catch, the stream stays writable |
Static: likely detected |
Pipe lifecycle: token passing, finally disposal, never-connected disposal, log disposal order |
No decisive test | Not evaluated | Unverified. A gap, not a proven defect. |
MSB6003 guard in Execute_OutputFileCreationFailureFailsTask |
Harness overrides ExecuteTool and never launches a process |
— | Observation: this guard cannot fail for the reason it names. The other assertions carry the protection. |
PACKAGE.md wording |
None | — | Not applicable (documentation) |
🧵 Parallel safety
STATUS: CLEAN. The specialist found the assembly MethodLevel (Workers 0) with no .runsettings, testconfig.json, or DoNotParallelize override. The new tests use per-test fixtures, stubs, and mocks. The class-level read lock on the shared MSBuild compatibility cache covers the one shared static it reaches. Analyzer firing was not confirmed by a build.
Per-test assessment
Pseudo-mutation evidence is static prediction only.
| Result | Quality | Test | Notes | Follow-up |
|---|---|---|---|---|
| Failed | D (60–69) | new InvokeTestingPlatformTaskTests.Execute_OutputFileCreationFailureFailsTask |
Final assertions branch on hasModule, so one method encodes two outcomes. |
Use fixed per-row expectations; see inline request. |
| Pass | A (90–100) | new InvokeTestingPlatformTaskTests.Execute_UniqueLogCreationFailureFailsTask |
Exact single error and no created file. | None |
| Pass | A (90–100) | new InvokeTestingPlatformTaskTests.Execute_ModuleInfoRetryCreatesLogAfterFailedFirstAttempt |
Exact single error and the exact retry log path. | None |
| Pass | B (80–89) | new InvokeTestingPlatformTaskTests.Execute_OutputWriterInitializationFailureDisposesStreamAndFailsTask |
Asserts disposal and the reported flush message, without an error count. | No change justified: the disposal assertion protects the claimed contract. |
One inline improvement request is queued for the hasModule branch. No other inline findings were found.
This advisory review is heuristic and non-blocking.
🤖 Automated content by GitHub Copilot. Generated by the Test Quality Review on PR (on open / sync) workflow. · copilot · routed: haiku55 xhigh · ~177 AIC · ⌖ ~2 AIC · ⊞ 15.9K
| Assert.Contains(error => error.Message!.Contains(message, StringComparison.Ordinal), errors); | ||
| // ToolTask reports exceptions that escape the task as MSB6003; the failure must be handled by the task itself. | ||
| Assert.DoesNotContain(error => error.Code == "MSB6003", errors); | ||
| if (hasModule) |
There was a problem hiding this comment.
🧪 Test review · Improvement · Grade D (60–69): The final assertions branch on hasModule, so one data-driven test checks two different outcomes. The shared failure contract (result, message, no MSB6003) is correct, but the branch caps Structure at D.
Copilot Replace the if (hasModule) / else block after Execute() with fixed per-row expectations. Keep the shared checks for the false result, the message, and no MSB6003. Assert the expected error count per row (1 with a module, 2 without) and assert the run failed error only where the row expects it, without control flow in the test body. Acceptance: no if after Execute(), all four rows pass, and the rows still fail when TryInitializeOutputFile is reverted to the unhandled-exception path.
Replacement: none. This read-only review did not compile a replacement.
This comment has been minimized.
This comment has been minimized.
|
Final test-triage resolution — Azure Pipelines build 1708414 This final resolution supersedes any earlier preliminary comment. Analysis mode is full. Evidence is incomplete: two artifact downloads failed and the Windows unit-test results are absent, so the build is not clean. One actionable, deterministic Linux failure is confirmed. 1. Deterministic Linux MSBuild task failure (actionable, high confidence)
2. Windows application-model acceptance: fixture build failures (environmental, not test logic)
3. Expected fixture failures, not regressions
4. Crash evidence
Escalation
Next steps
Confidence: high for finding 1. Medium for the root cause of finding 2.
|
Pull request
Summary
Follow-up to #12710, stacked on it. It makes the MSBuild test task (
InvokeTestingPlatformTask) report its own failures and clean up its pipes and log.ModuleInfoRequest(for example from Retry) tries again.CancellationToken.None.Dispose()always runs (infinally). The log is closed only after the connection loop and servers stop.PACKAGE.mdnotes that a log creation failure is reported as an MSBuild error.Design and decision record
Robustness and lifetime fixes; no separate record.
Demonstration
Not applicable. No rendered output changes.
Validation and regression proof
Windows, Debug, repo SDK, on this commit:
Microsoft.Testing.Platform.MSBuild.UnitTests.exe, net10.0 and net11.0: 484 total, 479 passed, 5 skipped, 0 failed..\build.cmd -pack,Microsoft.Testing.Platform.Acceptance.IntegrationTests.exe --filter "FullyQualifiedName~MSBuildLogFileTests": 3/3. The existingMSBuildTests_Testcases passed on an earlier revision, exceptInvoke_TestTarget_With_Incompatible_Arch. That test hangs on this machine insideCreateProcessfor the arm64 app host, before any task code runs.Not run: Linux, macOS, and
MSBuild.exeon .NET Framework.Test-value evidence
src/MTP/Microsoft.Testing.Platform.MSBuildreverted to the base PR: 7 failures:Execute_OutputFileCreationFailureFailsTask(all 4 rows),Execute_UniqueLogCreationFailureFailsTask,Execute_ModuleInfoRetryCreatesLogAfterFailedFirstAttemptandExecute_OutputWriterInitializationFailureDisposesStreamAndFailsTask. All pass with the change.(True,*)rows ofExecute_OutputFileCreationFailureFailsTaskfail.Execute_ModuleInfoRetryCreatesLogAfterFailedFirstAttemptfails.finallyaroundDispose(), the dispose order, and disposing servers that never connected. These are hard to observe in a unit test.